<link rel="stylesheet" href="{{URL::asset('mobile/css/public.css') }}"/>
<link rel="stylesheet" href="{{URL::asset('mobile/css/rankdetail.css') }}"/>
<link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<style type="text/css">
.list-block {
	margin: 0;
} 
</style>
@include('mobile.title')
<div class="page-group">
    <div id="page-infinite-scroll-bottom" class="page">
		<div class="content infinite-scroll" data-distance="100">
		    <div class="list-block">
		      	<ul class="list-container">
					<!--<li></li>-->
		      	</ul>
		    </div>
		    <!-- 加载提示符 -->
		    <div class="infinite-scroll-preloader">
		      	<div class="preloader">
		      	</div>
		    </div>
		</div>
	</div>
</div>
<style type="text/css">
.page-group {
	height: 92%;
	top: 1.5rem;
	border-top: none;
}
.page, .page-group{
	background: #171922;
}
.list-block ul {
	background: #F6F6F6;
}
body section{
	border:none;
	background: #171922;
	margin-bottom: 0rem;
}
body section.title div:nth-child(1) {
  border-bottom: none;
  color: #9592A7;
}
body section.title div:nth-child(2) {
  border-bottom: 0.1rem solid #3B9CE0;
  color: #FFFFFF;
  height: 100%;
}
body section div.list div.type p:nth-child(1),
body section div.list div.direction p:nth-child(1) {
	color: #FFFFFF;
	font-size: 0.7rem;
}
body section div.list div.type p:nth-child(2),
body section div.list div.direction p:nth-child(2) {
	color: #717780;
	font-size: 0.55rem;
}
body section div.detail div.detail_top p {
  line-height: 1.4rem;
}
body section div.detail div.detail_bottom {
	border-bottom: 1px solid #2E303E;
	padding-left: 1rem;
}
body section div.detail div.detail_top,
body section div.detail div.detail_bottom {
	background: #171922;
	border-top: 1px solid #2E303E;
}
body section div.detail div.detail_top div.detail_top_left div p:nth-child(1),
body section div.detail div.detail_top div.detail_top_right div p:nth-child(1),
body section div.detail div.detail_top div.detail_top_left p:nth-child(1),
body section div.detail div.detail_top div.detail_top_right p:nth-child(1),
body section div.detail div.detail_top div.detail_top_left p:nth-child(1),
body section div.detail div.detail_top div.detail_top_right p:nth-child(1),
body section div.detail div.detail_bottom p:nth-child(1) {
	color: #c9ccd3;
	font-size: 0.55rem;
}
body section div.detail div.detail_top div.detail_top_left div.openprice p:nth-child(2),
body section div.detail div.detail_top div.detail_top_right div.closeprice p:nth-child(2),
body section div.detail div.detail_top div.detail_top_left div.onlyprofit p:nth-child(2),
body section div.detail div.detail_top div.detail_top_right div.opentime p:nth-child(2),
body section div.detail div.detail_top div.detail_top_left div.stoploss p:nth-child(2),
body section div.detail div.detail_top div.detail_top_right div.closetime p:nth-child(2),
body section div.detail div.detail_bottom p:nth-child(2) {
	color: #FFFFFF;
	font-size: 0.55rem;
}
body section div.detail div.detail_bottom .dingdannum {
  margin: 0;
}
</style>
<!-- js引入 -->
<script src="{{URL::asset('mobile/js/public.js') }}"></script>
<script src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script>
var pagess = 0;
var allpage = 2;
var loading = false;
var listurl       = '{{url("/handanhistory")}}';
var analyst_id   = '{{ $info[0]->id}}';
$(function () {
	'use strict';
	//无限滚动
	$(document).on("pageInit", "#page-infinite-scroll-bottom", function(e, id, page) {
//	    var loading = false;
    	// 每次加载添加多少条目
		var itemsPerLoad = 10;
    	// 最多可加载的条目
    	var lastIndex = $('.list-container li').length;
		pullupRefresh(0); //先加载一次数据
    	$(page).on('infinite', function() {
	      	// 如果正在加载，则退出
		  	if (loading) return;
		    // 设置flag
	      	loading = true;
	      	// 模拟1s的加载过程
	      	setTimeout(function() {
	        	// 重置加载flag
	        	loading = false;
	        	if (pagess >= allpage) {
	          		// 加载完毕，则注销无限加载事件，以防不必要的加载
	          		$.detachInfiniteScroll($('.infinite-scroll'));
	          		// 删除加载提示符
	          		$('.infinite-scroll-preloader').html('已加载全部');
	          		return;
	        	}
	        	pagess++; //页面+1
	        	pullupRefresh(0);//更新数据
	        	// 更新最后加载的序号
	        	lastIndex = $('.list-container li').length;
	        	$.refreshScroller();
	      	}, 1000);
	    });
	});
	//加载提示符
	$(document).on("pageInit", "#page-preloader", function(e, id, page) {
	    $(page).on('click','.open-preloader-title', function () {
	      	$.showPreloader('加载中...')
	      	setTimeout(function () {
	        	$.hidePreloader();
	      	}, 2000);
	    });
	    $(page).on('click','.open-indicator', function () {
	      	$.showIndicator();
	      	setTimeout(function () {
	        	$.hideIndicator();
	      	}, 2000);
	    });
	});
  	$.init();
});
var select_type = 0, //交易类型 全局变量
      select_dealtype = 0; //订单盈利亏损 全局变量
//筛选方法
function handanlist(type,dealtype,obj,sq){  
	pagess = 0;
	//调取数据筛选
	select_type = type;  //买入卖出类型
	select_dealtype = dealtype;  //盈亏类型
	pullupRefresh(1);
	// 小对号，修I改样式
	$(obj).siblings().each(function(){
		$(this).html($(this).text());
	});
	if(sq == 1){
		$('.zheng').html($(obj).text()+' <img src="{{ URL::asset("mobile/image/analystcenter/s.png") }}" />');
	}else{
		$('.ying').html($(obj).text()+' <img src="{{ URL::asset("mobile/image/analystcenter/s.png") }}" />');	
	}
	$(obj).html($(obj).text()+' <img src="{{ URL::asset("mobile/image/analystcenter/duihao.png") }}" />');
	$('.j_box').hide();
}
//数据加载
function pullupRefresh(num){
	var id  = "{{$info[0]-> id}}";
	$.ajax({
        url: listurl,
        type: "get",
        data:  {analyst_id:id,type:select_type,dealtype:select_dealtype,typename:'',page:pagess},
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        dataType:'json',
        success: function (data) {
        	allpage = data.allpage;
        	if(allpage < 2){
        		$('.infinite-scroll-preloader').html('已加载全部');
        	}else{
        		$('.infinite-scroll-preloader').html('<div class="preloader"></div>');
        	}
            var str='';
            var dataArr = data.arr;
            	if(data){
            		for(var i=0;i<dataArr.length;i++) {
	            		var data = dataArr;
						str+='<li onclick="langxue(this)"><section><div class="list">';
						str+='<div class="type"><p>'+data[i].chinaname+'</p><p>'+data[i].typename+'</p></div>'; //品种英文
						str+='<div class="direction">';
						if(data[i].buy_status == 1){
	                        str += '<p>卖出</p>';
	                    }else{
	                        str += '<p>买入</p>';
	                    }
						str+='<p>方向</p></div>';
						str+='<div class="profit">';
						if(data[i].final_point >0 ){
	                        str += '<div style="color:#F0364C;">'+data[i].final_point+'</div>';
	                    }else{
	                        str += '<div style="color:#3EB581;">'+data[i].final_point+'</div>';
	                    }
						str+='<p>盈利</p></div></div>';
						str+='<div class="detail"><div class="detail_top"><div class="detail_top_left">';
						str+='<div class="openprice"><p>开仓价</p><p>'+data[i].begin_point+'</p></div>'; //开仓价格
						str+='<div class="onlyprofit"><p>止&nbsp;&nbsp;&nbsp;盈</p><p>'+data[i].target_profit_point+'</p></div>';
						str+='<div class="stoploss"><p>止&nbsp;&nbsp;&nbsp;损</p><p>'+data[i].target_loss_point+'</p></div></div>';
						str+='<div class="detail_top_right">';
						str+='<div class="closeprice"><p>平&nbsp;&nbsp;仓&nbsp;&nbsp;价</p><p>'+data[i].end_point+'</p></div>'; //平仓价格
						str+='<div class="opentime"><p>开仓时间</p><p>'+UnixToDate(data[i].begin_time,false,'',1)+' '+UnixToDate(data[i].begin_time,true,'',0)+'</p></div>';
						str+='<div class="closetime"><p>平仓时间</p><p>'+UnixToDate(data[i].end_time,false,'',1)+' '+UnixToDate(data[i].end_time,true,'',0)+'</p></div></div></div>';
						str+='<div class="detail_bottom"><div class="dingdannum"><p>订单号:</p><p>'+data[i].tradeid+'</p></div></div></div></section></li>';
					}
            	}else{
            		$('.list-container').html('sorry，没有更多数据了');
            	}
				if(num == 1){
					$('.list-container').html(str);
				}else{
					$('.list-container').append(str);
				}
			}
     	});
};
//时间转换方法
function UnixToDate(unixTime, isFull, timeZone,type) {
    if (typeof (timeZone) == 'number')
    {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis = "";
    if(type){
        ymdhis += time.getFullYear() + ".";
        ymdhis += (time.getMonth()+1)>9?(time.getMonth()+1)+'.':'0'+(time.getMonth()+1) + ".";
        ymdhis += time.getDate()>9?time.getDate():'0'+time.getDate();
    }
    if (isFull === true)
    {
        ymdhis += " " + time.getHours()>9?time.getHours()+ ":":'0'+time.getHours() + ":";
        ymdhis += time.getMinutes()>9?time.getMinutes()+ ":":'0'+time.getMinutes() + ":";
        ymdhis += time.getSeconds()>9?time.getSeconds():'0'+time.getSeconds();
    }
    return ymdhis;
}     
function langxue(obj) {
	$(obj).find('.detail').toggle();
}
</script>  	
